package com.syg.logback.core;

import com.syg.boot.util.time.DateUtil;
import com.syg.logback.consts.FileStepExeTypeEnum;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author syg
 * @version 1.0
 * @date 2021年11月24日19:14:46
 */
public class FileMonitorStepBuilder implements Serializable {

    private static final long serialVersionUID = 1982909421574882622L;
    private String flowId;
    private String bizNo;
    private String fileNo;
    private String exeType;
    private String exeSts = "S";
    private String startTime;
    private String description;

    public FileMonitorStepBuilder() {
    }

    public FileMonitorStepBuilder setFlowId(String flowId) {
        if (StringUtils.isBlank(flowId)) {
            flowId = null;
        }

        this.flowId = flowId;
        return this;
    }

    public FileMonitorStepBuilder setBizNo(String bizNo) {
        if (StringUtils.isBlank(bizNo)) {
            bizNo = null;
        }

        this.bizNo = bizNo;
        return this;
    }

    public FileMonitorStepBuilder setFileNo(String fileNo) {
        if (StringUtils.isBlank(fileNo)) {
            fileNo = null;
        }

        this.fileNo = fileNo;
        return this;
    }

    public FileMonitorStepBuilder setExeType(FileStepExeTypeEnum fileStepExeTypeEnum) {
        this.exeType = fileStepExeTypeEnum.getCode();
        return this;
    }

    public FileMonitorStepBuilder setExeStsSucc() {
        this.exeSts = "S";
        return this;
    }

    public FileMonitorStepBuilder setExeStsFail() {
        this.exeSts = "F";
        return this;
    }

    public FileMonitorStepBuilder setStartTime(Date startTime) {
        this.startTime = DateUtil.DEFAULT_ON_SECOND_FORMAT.format(startTime);
        return this;
    }

    public FileMonitorStepBuilder setStartTime(LocalDateTime startTime) {
        this.startTime = startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        return this;
    }

    public FileMonitorStepBuilder setDescription(String description) {
        if (StringUtils.isNotBlank(description)) {
            if (description.length() >= 2000) {
                description = description.substring(0, 2000);
            }
        } else {
            description = null;
        }

        this.description = description;
        return this;
    }

    public FileMonitorStep build() {
        return new FileMonitorStep(this);
    }

    public String getFlowId() {
        return this.flowId;
    }

    public String getBizNo() {
        return this.bizNo;
    }

    public String getFileNo() {
        return this.fileNo;
    }

    public String getExeType() {
        return this.exeType;
    }

    public String getExeSts() {
        return this.exeSts;
    }

    public String getStartTime() {
        return this.startTime;
    }

    public String getDescription() {
        return this.description;
    }
}
